<?php
require_once("checklogin.php");
require_once("classQuanTriTin.php");
$qt = new quantritin;
$district = $qt->District(-1);

$idCustomer=-1;
if (isset($_GET['idCustomer'])==false) die('Không biết khách hàng nào'); 
$idCustomer = $_GET['idCustomer']; 	
$customer = $qt->DetailCustomer($idCustomer);
$row_customer = mysql_fetch_assoc($customer);
if (isset($_POST['btnOK'])==true) {
	$qt->EditCustomer($idCustomer);
	header("location:main.php?p=customer_list");
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="../css/from_label.css" rel="stylesheet" type="text/css" />
<link href="../Scripts/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css" />
<!--
<script type="text/javascript" src="../Scripts/jquery.js"></script>
<script type="text/javascript" src="../Scripts/jquery-1.4.3.min.js"></script>
-->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>
<script type="text/javascript" src="ckfinder_user/ckfinder.js"></script>
<script type="text/javascript" src="../Scripts/jquery.ui.core.js"></script>
<script type="text/javascript" src="../Scripts/jquery.ui.datepicker.js"></script>
<script type="text/javascript" src="ckeditor/ckeditor.js"></script>

<!-- FOR IPHONE -->
<link href="../Scripts/iphone/iphone.css" rel="stylesheet" type="text/css">
<!-- <link href="../Scripts/iphone/iphone_styles.css" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> -->
<script type="text/javascript" src="../Scripts/iphone/iphone.js"></script>
<script type="text/javascript" src="../Scripts/iphone/iphone_script.js"></script>
<!-- END FOR IPHONE -->


<script type="text/javascript">
function BrowseServer( startupPath, functionData ){
	var finder = new CKFinder();
	finder.basePath = 'ckfinder/'; //Đường path nơi đặt ckfinder
	finder.startupPath = startupPath; //Đường path hiện sẵn cho user chọn file
	finder.selectActionFunction = SetFileField; // hàm sẽ được gọi khi 1 file được chọn
	finder.selectActionData = functionData; //id của text field cần hiện địa chỉ hình
	//finder.selectThumbnailActionFunction = ShowThumbnails; //hàm sẽ được gọi khi 1 file thumnail được chọn	
	finder.popup(); // Bật cửa sổ CKFinder
} //BrowseServer

function SetFileField( fileUrl, data ){
	document.getElementById( data["selectActionData"] ).value = fileUrl;
}
function ShowThumbnails( fileUrl, data ){	
	var sFileName = this.getSelectedFile().name; // this = CKFinderAPI
	document.getElementById( 'thumbnails' ).innerHTML +=
	'<div class="thumb">' +
	'<img src="' + fileUrl + '" />' +
	'<div class="caption">' +
	'<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' +
	'</div>' +
	'</div>';
	document.getElementById( 'preview' ).style.display = "";
	return false; // nếu là true thì ckfinder sẽ tự đóng lại khi 1 file thumnail được chọn
}

</script>
<script>
//For birthday customer
$(document).ready(function() {
	$("#Ngay").datepicker({
		numberOfMonths: 1,  dateFormat: 'dd/mm/yy',
		monthNames: ['Một','Hai','Ba','Tư','Năm','Sáu','Bảy','Tám','Chín', 
		'Mười','Mười một','Mười hai'] ,
		monthNamesShort: ['Tháng1','Tháng2','Tháng3','Tháng4','Tháng5',
		'Tháng6','Tháng7','Tháng8','Tháng9','Tháng10','Tháng11','Tháng12'] ,
		dayNames: ['Chủ nhật', 'Thứ hai', 'Thứ ba', 'Thứ tư', 'Thứ năm',
		 'Thứ sáu', 'Thứ bảy'],
		dayNamesMin: ['CN', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7'] ,
		showWeek: true , showOn: 'both',
		changeMonth: true , changeYear: true,
		currentText: 'Hôm nay', weekHeader: 'Tuần'
	});
});

//For birthday baby
$(document).ready(function() {
	$("#NgayBaby").datepicker({
		numberOfMonths: 1,  dateFormat: 'dd/mm/yy',
		monthNames: ['Một','Hai','Ba','Tư','Năm','Sáu','Bảy','Tám','Chín', 
		'Mười','Mười một','Mười hai'] ,
		monthNamesShort: ['Tháng1','Tháng2','Tháng3','Tháng4','Tháng5',
		'Tháng6','Tháng7','Tháng8','Tháng9','Tháng10','Tháng11','Tháng12'] ,
		dayNames: ['Chủ nhật', 'Thứ hai', 'Thứ ba', 'Thứ tư', 'Thứ năm',
		 'Thứ sáu', 'Thứ bảy'],
		dayNamesMin: ['CN', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7'] ,
		showWeek: true , showOn: 'both',
		changeMonth: true , changeYear: true,
		currentText: 'Hôm nay', weekHeader: 'Tuần'
	});
});

//For plan born
$(document).ready(function() {
	$("#NgayDuSinh").datepicker({
		numberOfMonths: 1,  dateFormat: 'dd/mm/yy',
		monthNames: ['Một','Hai','Ba','Tư','Năm','Sáu','Bảy','Tám','Chín', 
		'Mười','Mười một','Mười hai'] ,
		monthNamesShort: ['Tháng1','Tháng2','Tháng3','Tháng4','Tháng5',
		'Tháng6','Tháng7','Tháng8','Tháng9','Tháng10','Tháng11','Tháng12'] ,
		dayNames: ['Chủ nhật', 'Thứ hai', 'Thứ ba', 'Thứ tư', 'Thứ năm',
		 'Thứ sáu', 'Thứ bảy'],
		dayNamesMin: ['CN', 'T2', 'T3', 'T4', 'T5', 'T6', 'T7'] ,
		showWeek: true , showOn: 'both',
		changeMonth: true , changeYear: true,
		currentText: 'Hôm nay', weekHeader: 'Tuần'
	});
});

$(document).ready(function(){
	$("#idDistrict").change(function(){
		var idDistrict=$(this).val();
		$("#idWard").load("customer_ward.php?idDistrict="+ idDistrict);
	});

});
</script>
</head>

<body>
<?php ob_start();?>
<!--BEGIN FFORM-->
<form id="form1" name="form1" method="post" action="">
<table width="912" id="themuser" border="0" align="center" cellpadding="4" cellspacing="0">
<tr> <td colspan="4" align="center">
  <div id="from_label_left"></div>
  <div id="from_label_right"></div>
  <div id="from_label_center"><span id="header">THÊM KHÁCH HÀNG</span></div>
</td> </tr>
<tr>
  <td colspan="4" align="left" class="customer">KHÁCH HÀNG</td>
  </tr>
<tr>
  <td align="right">Họ </td>
  <td><input name="Ho" type="text" class="input" id="Ho"  value="{Ho}" /></td>
  <td align="right">Tên</td>
  <td><input name="Ten" type="text" class="input" id="Ten"  value="{Ten}" /></td>
</tr>
<tr>
  <td align="right">Địa chỉ</td>
  <td><input name="sonha" type="text" class="sonha" id="sonha" value="{SoNha}"/>
    <input name="duong" type="text" class="duong" id="duong" value="{Duong}"/></td>
  <td align="right">Quận/Phường</td>
  
  <td>
  <select name="idDistrict" class="quan" id="idDistrict">
	<?php while ($row_district = mysql_fetch_assoc($district)) { ?>
    <option value = "<?php echo $row_district['idDistrict'];?>">
    	<?php echo $row_district['name'];?>
    </option>
    <?php } ?>
  </select>
  <script>
  $(document).ready(function() {
    $("#idDistrict").val({idDistrict});
	$("#idWard").load("customer_ward.php?idDistrict={idDistrict}",null, GanLoaiTin);
  });
	
  function GanLoaiTin() {  $("#idWard").val({idWard}); }		
  </script> 

  <select name="idWard" id="idWard" class="phuong">
    <option value="0">Chọn Phường</option>
  </select>

  </td>


  </tr>
<tr>
  <td align="right">Email</td>
  <td><input name="email" type="text" class="input" id="email" value="{Email}"/></td>
  <td align="right">Số điện thoại</td>
  <td><input name="phone" type="text" class="input" id="phone" value="{Phone}"/></td>
</tr>
<tr>
  <td width="106" align="right">Nghề nghiệp</td>
  <td width="210" align="right"><div align="left">
    <input name="career" type="text" class="input" id="career" value="{Career}"/>
  </div></td>
  <td align="right">Ngày sinh KH</td>
  <td><input type="text" class="input" name="Ngay" id="Ngay" value="{Bday}"/></td>
</tr>
<tr>
  <td align="right">Giới tính</td>
  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
	<?php 
        $sex = $row_customer['sex'];
        if ( (int) $sex==1 ) { 
            echo "<td class='fortd'><label for='SEX'></label><input type='checkbox' id='gioitinh' name='gioitinh' data-on='ANH' checked data-off='CHỊ'/>"; 
        } else { 
            echo "<td class='fortd'><label for='SEX'></label><input type='checkbox' id='gioitinh' name='gioitinh' data-on='ANH'  data-off='CHỊ' />"; 
        } 
    ?>
       
		<!--<td class="fortd"><label for="SEX"></label><input type="checkbox" id="gioitinh" name="gioitinh" data-on="ANH" checked data-off="CHỊ"/>-->
	
		<!--<td class="fortd"><label for="SEX"></label><input type="checkbox" id="gioitinh" name="gioitinh" data-on="ANH" data-off="CHỊ" checked />-->
		
		
      </tr>
    </table></td>
  <td align="right">Ngày dự sinh</td>
  <td><input type="text" class="input" name="NgayDuSinh" id="NgayDuSinh" value="{Pday}"/></td>
  </tr>
<tr>
  <td align="right">Tiềm năng</td>
  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
	<?php 
        $active = $row_customer['active']; 
        if ( (int) $active==1 ) { 
            echo "<td class='fortd'><label for='ACTIVE'></label><input type='checkbox' id='active' name='active' data-on='CÓ' checked data-off='KHÔNG'/>"; 
        } else { 
            echo "<td class='fortd'><label for='ACTIVE'></label><input type='checkbox' id='active' name='active' data-on='CÓ' data-off='KHÔNG'/>";
        } 
    ?>
      </tr>
    </table></td>
  <td align="right">Tham khảo</td>
  <td>
  <select name="idSource" class="refer" id="idSource">
    <?php while ($row_refer = mysql_fetch_assoc($refer)) { ?>
    <option value = "<?php echo $row_refer['idService'];?>"> <?php echo $row_refer['name'];?> </option>
    <?php } ?>
  </select>
  </td>
</tr>
<tr>
  <td align="right">Xuất hóa đơn</td>
  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>      
	<?php 
        $vat = $row_customer['vat']; 
        if ( (int) $vat==1 ) { 
            echo "<td class='fortd'><label for='VAT'></label><input type='checkbox' id='vat' name='vat' data-on='CÓ' checked data-off='KHÔNG'/>"; 
        } else { 
            echo "<td class='fortd'><label for='VAT'></label><input type='checkbox' id='vat' name='vat' data-on='CÓ' data-off='KHÔNG'/>";
        } 
    ?>
    </tr>
  </table></td>
  <td align="right">Sử dụng</td>
  <td><select name="idService" class="refer" id="idService">
    <?php while ($row_using = mysql_fetch_assoc($using)) { ?>
    <option value = "<?php echo $row_using['idService'];?>"> <?php echo $row_using['name'];?></option>
    <?php } ?>
  </select></td>
</tr>
<tr>
  <td colspan="4" align="center">
  

  </td>
</tr>
<tr>
  <td colspan="4" align="center"></td>
</tr>
<tr>
  <td colspan="4" align="left" class="customer2">EM BÉ</td>
</tr>
<tr>
  <td align="right">Họ </td>
  <td><input name="HoBaby" type="text" class="input" id="HoBaby" value="{HoBaby}"/></td>
  <td align="right">Tên</td>
  <td><input name="TenBaby" type="text" class="input" id="TenBaby" value="{TenBaby}"/></td>
</tr>
<tr>
  <td align="right">Giới tính</td>
  <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
     
	<?php 
        $gender_baby = $row_customer['gender_baby'];
        if ( (int) $gender_baby==1 ) { 
            echo "<td class='fortd'><label for='GENDER_BABY'></label><input type='checkbox' id='gender_baby' name='gender_baby' data-on='BÉ TRAI' checked data-off='BÉ GÁI'/>"; 
        } else { 
            echo "<td class='fortd'><label for='GENDER_BABY'></label><input type='checkbox' id='gender_baby' name='gender_baby' data-on='BÉ TRAI'  data-off='BÉ GÁI' />"; 
        } 
    ?>
  </tr>
  </table></td>
  <td align="right">Ngày sinh</td>
  <td><input type="text" class="input" name="NgayBaby" id="NgayBaby" value="{BdayBaby}"/></td>
</tr>
<tr>
  <td align="right">Sinh</td>
  <td>
     <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>    
	<?php 
        $method_baby = $row_customer['method_baby'];
        if ( (int) $method_baby==1 ) { 
            echo "<td class='fortd'><label for='BORN_METHOD'></label><input type='checkbox' id='born_method' name='born_method' data-on='MỔ' checked data-off='THƯỜNG''/>"; 
        } else { 
            echo "<td class='fortd'><label for='BORN_METHOD'></label><input type='checkbox' id='born_method' name='born_method' data-on='MỔ' data-off='THƯỜNG' />"; 
        } 
    ?>
      </tr>
    </table>
  </td>
  <td align="right">Con thứ</td>
  <td>
  	<input name="baby_level" type="radio" id="03" value="1" checked="checked" /> 1  
    <input name="baby_level" type="radio" id="13" value="2" /> 2
    <input name="baby_level" type="radio" id="13" value="3" /> 3
    <input name="baby_level" type="radio" id="13" value="4" /> 4
    <input name="baby_level" type="radio" id="13" value="5" /> 5
  </td>
 
</tr>
<tr>
  <td colspan="4" align="center">Tuổi: tính theo ngày (30 days = 1 month)</td>
</tr>
<tr>
  <td colspan="4" align="left" class="customer2">GHI CHÚ</td>
</tr>
<tr>
  <th colspan="4" align="right">
    <textarea name=TomTat id=TomTat class=txt /></textarea> 
    <script type="text/javascript">
        var editor2 = CKEDITOR.replace( 'TomTat',{
            uiColor : '#9AB8F3',
            language:'vi',
            skin:'office2003',
            
            //filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
            //filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
            //filebrowserImageUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
            //filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
                        
            toolbar:[
            //['Source','-','Save','NewPage','Preview','-','Templates'],
            //['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'],
            //['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
            
            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
            ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
            //['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
            //['Link','Unlink','Anchor'],
            //['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
            //['Styles','Format','Font','FontSize'],
            ['TextColor','BGColor'],
            //['Maximize', 'ShowBlocks','-','About']
            ]
        });		
   </script>    
   <script>		  		  	
	setTimeout("HienDuLieuTomTat()", 300);		
	function HienDuLieuTomTat(){
		var str= "{TomTat}";			
		var oEditor = CKEDITOR.instances.TomTat;			
		oEditor.setData( str);				
	}
	</script>
  </th>
</tr>

<!-- ĐÁNH GIÁ -->
<tr>
  <td colspan="4" align="left">&nbsp;</td>
</tr>
<tr>
  <td colspan="4" align="left" class="customer2">ĐÁNH GIÁ</td>
</tr>
<tr>
  <th colspan="4" align="right">
    <textarea name=DanhGia id=DanhGia class=txt /></textarea> 
    <script type="text/javascript">
        var editor3 = CKEDITOR.replace( 'DanhGia',{
            uiColor : '#9AB8F3',
            language:'vi',
            skin:'office2003',
            
            //filebrowserImageBrowseUrl : 'ckfinder/ckfinder.html?Type=Images',
            //filebrowserFlashBrowseUrl : 'ckfinder/ckfinder.html?Type=Flash',
            //filebrowserImageUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
            //filebrowserFlashUploadUrl : 'ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash',
                        
            toolbar:[
            //['Source','-','Save','NewPage','Preview','-','Templates'],
            //['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print'],
            //['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
            
            ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
            ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
            //['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
            //['Link','Unlink','Anchor'],
            //['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
            //['Styles','Format','Font','FontSize'],
            ['TextColor','BGColor'],
            //['Maximize', 'ShowBlocks','-','About']
            ]
        });		
   </script>    
   <script>		  		  	
	setTimeout("HienDuLieuDanhGia()", 300);		
	function HienDuLieuDanhGia(){
		var str= "{DanhGia}";			
		var oEditor = CKEDITOR.instances.DanhGia;			
		oEditor.setData( str);				
	}
   </script>
  </th>
</tr>
<!-- END ĐÁNH GIÁ -->

<tr><td colspan="4" align="center">
	<input type="reset" name="btnxoa" id="btnxoa" value=" Xoá " />
	<input type="submit" name="btnOK" id="btnOK" value="  OK  " />
</td>
</tr>
<tr>
  <td colspan="4" align="center">&nbsp;</td>
</tr>
</table>
</form>

<!--END FFORM-->
<?php
$str=ob_get_clean(); 
$str = str_replace("{idDistrict}" , $row_customer['idDistrict'],$str);
$str = str_replace("{idWard}" , $row_customer['idWard'],$str);
$str = str_replace("{Ho}" , $row_customer['lname'],$str);
$str = str_replace("{Ten}" , $row_customer['fname'],$str);
$str = str_replace("{SoNha}" , $row_customer['number'],$str);
$str = str_replace("{Duong}" , $row_customer['street'],$str);
$str = str_replace("{Email}" , $row_customer['email'],$str);
$str = str_replace("{Phone}" , $row_customer['phone'],$str);
$str = str_replace("{Career}" , $row_customer['career'],$str);
$str = str_replace("{Bday}" , $row_customer['bday'],$str);
$str = str_replace("{Pday}" , $row_customer['pday'],$str);

$str = str_replace("{HoBaby}" , $row_customer['lname_baby'],$str);
$str = str_replace("{TenBaby}" , $row_customer['fname_baby'],$str);
$str = str_replace("{BdayBaby}" , $row_customer['bday_baby'],$str);

$str = str_replace("{TomTat}" , ucfirst(strtolower($row_customer['summary'])),$str);
$str = str_replace("{DanhGia}" , $row_customer['evaluate'],$str);

$str = str_replace("{user}" , ($row_customer['idGroup']==0)? "checked=checked":"",$str);	
$str = str_replace("{admin}" , ($row_customer['idGroup']==1)? "checked=checked":"",$str);

$str = str_replace("{nu}" , ($row_customer['GioiTinh']==0)? "checked=checked":"",$str);
$str =str_replace("{nam}",($row_customer['GioiTinh']==1)? "checked=checked":"",$str);



echo $str;
?>
</body>
</html>
